package lxt.service.impl;

import java.util.List;

import lxt.dao.UserDao;
import lxt.entity.UserInfo;
import lxt.service.UserService;
/**
 * 用户管理service
 * @author Lit
 *
 */
public class UserServiceImpl implements UserService {

	private UserDao userDao;

	public UserInfo isExist(String name, String pwd) throws Exception {
		return this.userDao.isExist(name, pwd);
	}
	
	public boolean addUser(UserInfo user) throws Exception {
		this.userDao.save(user);
		return true;
	}

	public boolean deleteUser(String username,UserInfo user) throws Exception {
		String[] delId = username.split(",");
		for(int i=0;i<delId.length;i++){
			String id = delId[i];
			if(id.equals(user.getUsername())){
				return false;
			}
			this.userDao.delete(UserInfo.class, id);
		}
		return true;
	}

	public int loadAllUserCount(String username) throws Exception {
		return this.userDao.loadAllUserCount(username);
	}

	public List<UserInfo> loadUser(String username, int offset, int length)
			throws Exception {
		return this.userDao.loadAllUser(username, offset, length);
	}

	public UserInfo loadUserById(String username) throws Exception {
		return (UserInfo) this.userDao.get(UserInfo.class, username);
	}

	public boolean updateUser(UserInfo user) throws Exception {
		this.userDao.update(user);
		return true;
	}
	
	/**
	 * get set methods
	 * @return
	 */
	public UserDao getUserDao() {
		return userDao;
	}
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
}
